package fr.axones.pocketagile.ui.view.authentication
{
	import mx.validators.EmailValidator;
	import mx.validators.ValidationResult;
	
	import spark.components.TextInput;

	public class AuthenticationPasswordRecoveryViewHelper
	{
		public function AuthenticationPasswordRecoveryViewHelper()
		{
		}
		
		public static function validEmail(ti_email:TextInput):Boolean
		{
			if(ti_email.text.length == 0)
			{
				return false;
			}
			
			var a:Array = new EmailValidator().validate(ti_email.text).results;
			
			if(a == null || a.length == 0)
			{
				return true;
			}
			
			return (a[0] as ValidationResult).isError;
		}
		
		public static function validForm(ti_email:TextInput):String
		{
			var error:String = "";
			
			
			if(!validEmail(ti_email))
			{
				error += "email is not valid";
			}
			
			return error;
		}
		
		public static function buildPasswordRecoveryEvent(email:String):AuthenticationEvent
		{
			var e:AuthenticationEvent = new AuthenticationEvent(AuthenticationEvent.PASSWORD_RECOVERY);
			
			e.email = email;
			
			return e;
		}
	}
}